/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ee.cybertron.energon.components;

import com.ee.cybertron.energon.loader.LoaderSelectOneMenu;
import com.icesoft.faces.component.ext.HtmlSelectOneMenu;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ValueChangeEvent;
import javax.faces.event.ValueChangeListener;
import org.jdom.Element;

/**
 *
 * @author stevenziggiz
 */
public class CyberSelectOneMenu extends HtmlSelectOneMenu implements CyberComponent {
    
    private String tableReference;
    private String selectOptionValue;
    private String optionValueReference;
    private String optionLabelReference;
    private String dataType;
    private ValueChangeListener valueChangeListener;
    
    public CyberSelectOneMenu() {
        
    }
    
    @Override
    public void excute(Element XMLComponent) {
        boolean edit;
        Element XMLOption = XMLComponent.getChild("options", XMLComponent.getNamespace());
        this.tableReference = XMLComponent.getAttributeValue("tableReference");
        this.optionLabelReference = XMLOption.getAttributeValue("label");
        this.optionValueReference = XMLOption.getAttributeValue("value");
        this.dataType = XMLOption.getAttributeValue("type");
        getChildren().addAll(LoaderSelectOneMenu.obtenerItemsComboBox(tableReference, optionLabelReference, optionValueReference));
        edit = Boolean.valueOf(XMLComponent.getAttributeValue("edit"));
        this.setDisabled(!edit);
        valueChangeListener = new ValueChangeListener() {
            
            public void processValueChange(ValueChangeEvent vce) throws AbortProcessingException {
                selectOptionValue = (String) vce.getNewValue();
                setValue(vce.getNewValue());
            }
        };
        addValueChangeListener(valueChangeListener);
    }

    /**
     * @return the tableReference
     */
    public String getTableReference() {
        return tableReference;
    }

    /**
     * @param tableReference the tableReference to set
     */
    public void setTableReference(String tableReference) {
        this.tableReference = tableReference;
    }

    /**
     * @return the selectOptionValue
     */
    public String getSelectOptionValue() {
        return selectOptionValue;
    }

    /**
     * @param selectOptionValue the selectOptionValue to set
     */
    public void setSelectOptionValue(String selectOptionValue) {
        this.selectOptionValue = selectOptionValue;
    }

    /**
     * @return the optionValueReference
     */
    public String getOptionValueReference() {
        return optionValueReference;
    }

    /**
     * @param optionValueReference the optionValueReference to set
     */
    public void setOptionValueReference(String optionValueReference) {
        this.optionValueReference = optionValueReference;
    }

    /**
     * @return the optionLabelReference
     */
    public String getOptionLabelReference() {
        return optionLabelReference;
    }

    /**
     * @param optionLabelReference the optionLabelReference to set
     */
    public void setOptionLabelReference(String optionLabelReference) {
        this.optionLabelReference = optionLabelReference;
    }

    /**
     * @return the dataType
     */
    public String getDataType() {
        return dataType;
    }

    /**
     * @param dataType the dataType to set
     */
    public void setDataType(String dataType) {
        this.dataType = dataType;
    }
}
